In [1]:
import numpy as np
import plotly.io as pio
pio.renderers.default = "notebook"
In [2]:
from src.imgen import ImageGenerator
In [3]:
NUM_QUBITS = 6
NUM_LAYERS = 2

EPOCH_SAMPLE_SIZE = 10**4
BATCH_SAMPLE_SIZE = 10**3

pixel_art = np.array([
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 1, 0, 0],
    [0, 0, 1, 0, 0, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 0, 0, 0, 1, 0],
    [0, 1, 0, 0, 0, 0, 1, 0],
    [0, 0, 1, 1, 1, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0]
], dtype=np.float)
In [4]:
imgen = ImageGenerator(
    NUM_QUBITS, NUM_LAYERS,
    epoch_sample_size=EPOCH_SAMPLE_SIZE, batch_sample_size=BATCH_SAMPLE_SIZE,
    enable_remapping=True
)
In [5]:
imgen.load_image(pixel_art, blur_sigma=0.6, show_figure=True)
In [6]:
NUM_EPOCHS = 300

imgen.train(imgen.make_dataset(), NUM_EPOCHS, show_progress=True)
Training epoch 300 of 300:
In [7]:
imgen.plot_output_distribution_history()
In [8]:
imgen.plot_loss_history()
In [9]:
imgen.plot_final_output_distribution(avg_window=5)
In [10]:
imgen.get_final_params(avg_window=10)
Out[10]:
array([[[-0.9384098 , -0.5035613 , -0.15809385, -0.28780526,
         -0.03601963,  0.02702333],
        [ 0.00429374, -0.08270335,  0.22732046, -0.0769777 ,
          0.17950357, -0.0446505 ]]], dtype=float32)